package com.todo.strategy.online.application.handler.relation;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.delicacy.service.api.request.QueryRestaurantDetailByIdRequest;
import com.todo.delicacy.service.api.response.RestaurantDetailResponse;
import com.todo.strategy.common.enums.StrategyRelationTypeEnum;
import com.todo.strategy.online.application.entity.context.RelationSimpleContext;
import com.todo.strategy.online.application.remote.RestaurantInfoRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2024/7/3 13:55
 * @description
 */
@Slf4j
@Component
public class FoodRelationHandle extends StrategyRelationStrategy {

    @Resource
    private RestaurantInfoRemoteService restaurantInfoRemoteService;


    @Override
    protected StrategyRelationTypeEnum handleName() {
        return StrategyRelationTypeEnum.FOOD;
    }

    @Override
    protected RelationSimpleContext doHandle(Long relationId) {
        if (relationId == null || relationId < 0) {
            return null;
        }
        QueryRestaurantDetailByIdRequest request = new QueryRestaurantDetailByIdRequest();
        request.setRestaurantId(relationId);
        BizResponse<RestaurantDetailResponse> bizResponse = restaurantInfoRemoteService.queryRestaurantDetailById(request);
        if (bizResponse == null || !bizResponse.isSuccess() || bizResponse.getData() == null) {
            log.warn("FoodRelationHandle#doHandle 根据关联Id查询饭店详情信息完成 数据为空 默认返回空 relationId:【{}】", relationId);
            return null;
        }
        RestaurantDetailResponse restaurantDetailResponse = bizResponse.getData();
        RelationSimpleContext context = new RelationSimpleContext();
        context.setName(restaurantDetailResponse.getName());
        context.setCity(restaurantDetailResponse.getCity());
        context.setAddress(restaurantDetailResponse.getAddress());
        context.setLon(restaurantDetailResponse.getLon());
        context.setLat(restaurantDetailResponse.getLat());
        context.setRemark(restaurantDetailResponse.getDesc());
        context.setRelationType(StrategyRelationTypeEnum.FOOD);
        return context;
    }
}
